package com.activenetwork.util.grid.condition;


import java.util.Collection;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

/**
 * 
 * Condition {@link #matchs(WebElement)} will return <code>true</code> if
 * {@link #collection} contains string in {@link #column}
 * 
 */
public class ContainCondition implements Condition {

	private int column;
    private Collection<String> collection;
    
    public void setColumn(int column) {
		this.column = column;
	}
	public void setCollection(Collection<String> collection) {
		this.collection = collection;
	}
	public int getColumn(){
		return this.column;
	}
	public Collection<String> getCollection(){
		return this.collection;
	}
    /**
     * Empty constructor
     */
    public ContainCondition(){
    	this.collection = null;
    	this.column = -1;
    }
    /**
     * Direct constructor
     * @param column
     * @param collection
     */
    public ContainCondition(int column, Collection<String> collection) {
        this.column = column;
        this.collection = collection;
    }
    
    @Override
    public boolean matchs(WebElement row) {
        boolean flag = false;
        if (collection.contains(row.findElement(
                By.xpath("./td[" + column + "]")).getText())) {
            flag = true;
        }
        return flag;
    }
}
